package com.feng.springboot01.controller;

import com.feng.springboot01.dao.EmployeeDao;
import com.feng.springboot01.pojo.Department;
import com.feng.springboot01.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Collection;
import java.util.Map;

@Controller
public class MyWebController {

    @Autowired
    EmployeeDao employeeDao;

    @RequestMapping("/main")
    public String login(@RequestParam  String username,@RequestParam String password, Model model, HttpSession httpSession){
            if (password.equals("123456")){
                httpSession.setAttribute("user",username);
                return "redirect:/main.html";
            }
            model.addAttribute("status","用户名或密码错误");
            return "/login";
    }

    //员工页面
    @RequestMapping("/employee.html")
    public String employees(Model model){
        Collection<Employee> allEmployee = employeeDao.getAllEmployee();
        model.addAttribute("employees",allEmployee);
       return "/emp/employee";
    }

    @RequestMapping("/logOut")
    public String logOut(HttpSession httpSession){

        if (httpSession.getAttribute("user")!=null){
            httpSession.removeAttribute("user");
        }
        return "redirect:/";
    }
}
